#define MDNS_NAME "esp32"
#define NEOPIXEL_PIN 4
#define WIDTH 8
#define HEIGHT 8
#define ZIGZAG_MATRIX
#define Touch 2
 
#include <ESPmDNS.h>
#include <WebServer.h>
#include <WiFiMulti.h>
#include "ESPAsyncWebServer.h"
#include <WebSocketsServer.h>
#include <Adafruit_NeoPixel.h>
#include <WiFiManager.h> 
#include "SPIFFS.h"
#include <ArduinoJson.h>


#define DATA "{\"colorList\":[\"000000000\",\"029043083\",\"126037083\",\"000135081\",\"171082054\",\"095087079\",\"194195199\",\"255241232\",\"255000077\",\"255163000\",\"255255039\",\"000231086\",\"041173255\",\"131118156\",\"255119168\",\"255204170\"],\"AllEmojis\":[\"0677776067777776707777077077770777777777770000777777777777077077\",\"00aaaa000aaaaaa0a0aaaa0aa0aaaa0aaaaaaaaaa0aaaa0a0a0000a000aaaa00\",\"088008807788888878888888e88888880e888880008888000008800000000000\",\"009aa90000aa900009a900000aa000009aaaaa900000a900000a900000090000\",\"0222222022ff022222ff0f2202fff22208888f22f88888f00088880000f00f00\",\"000ff000000ff000000ff000ff449f00ffff4fffffff4fffffff4ff00ff4ff00\",\"0077770007777770077007700770077007700770077007700777777000777700\",\"0000007700001707011101001dd110101d111100111111001111110001111000\",\"0076660007600660060000600660066000666600000660000006660000066d00\",\"77611677770000777700007760d00d0610000001100000016000000677700777\",\"0000000080000008880000880800008000000000800880080888888000800800\",\"00aaaa000aaaaaa0a0aaaa0aaa0aa0aaaaaaaaaaaaa00aaa0a0aa0a000aaaa00\",\"0880088078008888e88808888880888808880880008088000000800000000000\",\"0006660000666660006666606666666600000000c00c00c0000000000c00c00c\",\"4444440004f0f4000ff0ff000ffff00000cccc000fccc0f000ddd00000d0d000\",\"0ffff000ffffff00ffffffffffffffffffffff00044ff00000ff000000ff0000\",\"0007700000777000007770000007700000077000000770000077770000777700\",\"0077780007777870887778776877787766877787668777880626777000266600\",\"00cccc6000c66c7c0cccc67c0cccc7c0cccc67c0cccc7c00c6667c000cccc000\",\"77777777e8e77e8e888ee8888888888888888888788888877788887777788777\",\"0008800000888800088888808888888822288222000882000008820000022200\",\"00aaaa000aaaaaa0a00aa00aacaaaacaacaaaacaaaa00aaa0aa00aa000aaaa00\",\"0004000000044000004450000055440004444440044455505555444444444444\",\"9909909990aaaa090aaaaaa09aaaaaa99aaaaaa90aaaaaa090aaaa0999099099\",\"00ccc0000ccc0c000ccc0c00aacccc000ccccccc0ccc1cc000ccc10000a00a00\",\"000000ff000000ff000000ff00ff44440ff4ffff0ff444ff099994ff0009fff0\",\"0077770007777770077007700000077000077700007770000777777007777770\",\"0474440047447440644447446244444422244477222247240222622200226222\",\"0008800000088000008778000087780008877880088888808887788888888888\",\"777117777710017771000017d000000d0000000000000000d106601d77700777\",\"0088888800288888002288880008888800888288088822280282202200220002\",\"00aaaa000aaaaaa0a0aaaa0a0a0aa0a0aaaaaaaaa000000a0a0000a000aaaa00\",\"00b00b003bbbbbb0b0b00b003bbbbbb300b00b0b00b00b0bbbbbbbb300b00b00\",\"0007000000777000000700700707777777777070070070000007770000007000\",\"04000040042004e004424ee004444440204404404044044424e4444002044200\",\"000ff0ff000ff0ff0000f4f400ff44440ff4ffff0ff444ff099994ff0009fff0\",\"0077770007777770077007700000770000007770077007700777777000777700\",\"007dd70007777770d77dd77d77dddd77d70011761d60166101dddd1000dddd00\",\"0088880088288288889aa98888288288008888000000b0000b30b0b000b3b300\",\"777ee77777e88e777e8888e7e888888ee888888e7e8888e777e88e77777ee777\",\"0077cc0003c3cc7033333cc73333ccccc3cccccccc3c333c0ccc333000ccc300\",\"00aaaa000aaaaaa0a0aaaa0aa0aaaa0aaaaaaaaaaaaa00aa0a00aaa000aaaa00\",\"0777777077777777770000770000007700077770000770000000000000077000\",\"000c0000000c0000007cc000077ccc00c7ccccc0ccccccc0c7ccccc00ccccc00\",\"0000000000774220027404227774042200744422727777220e2077220ee67777\",\"000a90000077a9000077a90000aaaa000999944009aaa990aa4444990044a900\",\"0077770000777700077077000770770077777770777777700000770000007700\",\"00bb7b000bbbb7703bbbbbbb3bb777bb337bbb7b336bbb730d3336d000333d00\",\"00000fe000006eee000aa6ee00aaa9d00f9a99000ff49000dff90000dd000000\",\"d117711d777777777117711777777777611771166666666666666666d666666d\",\"0000000000ee88000ee8888088222288022762200888888000e8880000000000\",\"0088880008888880808888088808808888888888880000880800008000888800\",\"0007700000777700007777000077770000077000000770000000000000077000\",\"000000000099900009aaa9009aaaddd09aad666d9aad666609d66666dd666666\",\"0097a9007a97a9aaa09aa90a909aa90a04999990004999000004400000999900\",\"0000000007ccccd0777ccddd7777dddddddd111c0ddd11c000dd1c00000dc000\",\"0777770007777700077000000777770007777770000007700777777007777700\",\"0099490009949990949499492222224992929922429299240542445000525200\",\"0777777077777777777777777070707777777777077777700000770000007000\",\"d117711d777777777771177777777777611771166666666666666666d666666d\",\"00007000000760008807600080866d668886d660000880000008080000088800\",\"00aaaa000aaaaaa0a0aaaa0aa0aaaa0aeeaaaaeeeeaaaaee0aa00aa000aaaa00\",\"000cc000000cc000cccccccc0cccccc000cccc000cccccc00cc00cc00c0000c0\",\"0067770006760060677000007770000077700000677600060677776000666600\",\"0007a0000009900007a44aa07887a88aa887a88a922aa229092992909aa7aaa9\",\"760000777660076607d17660001766006076610606661d60046006404006d004\",\"0077770007777700077000000777770007777770077007700777777000777700\",\"0066660006707760677077766770707667700776677777760677776000666600\",\"0676666006766660d11dd11dd1d76d1dd6d76d6d06dddd6006766660066dd660\",\"d777777d711771177777777771177117677777766666666666666666d666666d\",\"0800080000888008800000800800008008000080080000088008880000800080\",\"00aaaa000aaaaaa0a00aa00aaaaaaaaaaaaaaaaaa000000a0aaa88a000aa8800\",\"0000dddd0000dddd0000d0000000d0000000d0000dddd000ddddd000dddd0000\",\"0000000000bb0bb00bbb3bbb0bbb3bbb0033b3300bbb3bbb0bbb3bbb00bb0bb0\",\"0000600000060060006006000060600600660060066666006660000066000000\",\"777766667ddd11167ddd11166ddd11166ddd11176ddd111706dd1d7000666700\",\"0777777007777770000007700000770000007700000770000007700000077000\",\"0000000077777777d777777d6d7777d670d77d07d77dd77d7777777700000000\",\"66066066666666660dddddd006666660066dd66006d99d6006d99d6006d99d60\",\"d777711d777777777771177777777777611777766666666666666666d666666d\",\"0000003b000000bb000003b300000b30bb00b3003b3bb00003bb300000b30000\",\"00aaaa000aaaaaa0a0aaaa0aa0aaaa0aaaaaaaaaaaa00aaa0a0aa0a000aaaa00\",\"00000ddd00dddddd00ddd00d00d0000d00d0000d00d00dddddd00dd0dd000000\",\"000b3000003b310000b3330003bb33100b3333303bbb33310004200000242200\",\"0000006700000667000066670006666700666670066677006660000066000000\",\"0dddd000d676dd00d7766d00d6666d00dd76dd000dddd0400000024400000024\",\"0077770007777770077007700077770007777770077007700777777000777700\",\"ccccc100111c100000c100000c100ccccccc10c111111c100000cccc00c01111\",\"0088066000888860088886200888876288886770068870700666707000067000\",\"d117777d777777777777777777777777677771166666666666666666d666666d\",\"0000008288000888028088820028820000288000008228000800008080000002\",\"00aaaa000aaaaaa070000700000aa000000aa000aaaaaaaa0a0000a000aaaa00\",\"00080000000800000089080008898980898a998889a77a9889a77a98089aa980\",\"067777606777777677777777d007700dd0d66d0d777007770777777007077070\",\"000666600067766600676666006666d60d666dd606666660666d000066000000\",\"00000d6d0d0006061d0d0d6dd100600060060d006d60000067d01dd07666d100\",\"0077770007777770077007700777777000777770000007700077777000777700\",\"880000888880088802222220fff82fff099829900ff82ff00ff82ff00ff82ff0\",\"0000000000888800088886280666268d0777288d888888007667d0000d00d000\",\"d777777d777227777728827777788777677777766666666666666666d666666d\"],\"diyEmojis\":[\"0677776067777776707777077077770777777777770000777777777777077077\",\"00aaaa000aaaaaa0a0aaaa0aa0aaaa0aaaaaaaaaa0aaaa0a0a0000a000aaaa00\",\"088008807788888878888888e88888880e888880008888000008800000000000\",\"009aa90000aa900009a900000aa000009aaaaa900000a900000a900000090000\",\"000000000f000f000ffffff00f1fff100effffe0002220000088800000f0f000\"],\"likedEmojis\":[\"0677776067777776707777077077770777777777770000777777777777077077\",\"00aaaa000aaaaaa0a0aaaa0aa0aaaa0aaaaaaaaaa0aaaa0a0a0000a000aaaa00\",\"088008807788888878888888e88888880e888880008888000008800000000000\",\"009aa90000aa900009a900000aa000009aaaaa900000a900000a900000090000\",\"000000000f000f000ffffff00f1fff100effffe0002220000088800000f0f000\"]}"


#define NUM0 "0077770007777770077007700770077007700770077007700777777000777700"
#define NUM1 "0007700000777000007770000007700000077000000770000077770000777700"
#define NUM2 "0077770007777770077007700000077000077700007770000777777007777770"
#define NUM3 "0077770007777770077007700000770000007770077007700777777000777700"
#define NUM4 "0077770000777700077077000770770077777770777777700000770000007700"
#define NUM5 "07777700077777000770000007777700077777700000077007777770077777000"
#define NUM6 "0077770007777700077000000777770007777770077007700777777000777700"
#define NUM7 "0777777007777770000007700000770000007700000770000007700000077000"
#define NUM8 "0077770007777770077007700077770007777770077007700777777000777700"
#define NUM9 "0077770007777770077007700777777000777770000007700077777000777700"

// 恶臭代码 实在是不想动脑子了 下次一定改
// 好像还不错? 挺方便的 不改了↑ 真香🤣
int angle = 0;
// 用于图案和屏幕灯珠顺序对应
const int angle0[64] = {0,1,2,3,4,5,6,7,15,14,13,12,11,10,9,8,16,17,18,19,20,21,22,23,31,30,29,28,27,26,25,24,32,33,34,35,36,37,38,39,47,46,45,44,43,42,41,40,48,49,50,51,52,53,54,55,63,62,61,60,59,58,57,56};
const int angle90[64] = {56,48,40,32,24,16,8,0,1,9,17,25,33,41,49,57,58,50,42,34,26,18,10,2,3,11,19,27,35,43,51,59,60,52,44,36,28,20,12,4,5,13,21,29,37,45,53,61,62,54,46,38,30,22,14,6,7,15,23,31,39,47,55,63};
const int angle180[64] = {63,62,61,60,59,58,57,56,48,49,50,51,52,53,54,55,47,46,45,44,43,42,41,40,32,33,34,35,36,37,38,39,31,30,29,28,27,26,25,24,16,17,18,19,20,21,22,23,15,14,13,12,11,10,9,8,0,1,2,3,4,5,6,7};
const int angle270[64] = {7,15,23,31,39,47,55,63,62,54,46,38,30,22,14,6,5,13,21,29,37,45,53,61,60,52,44,36,28,20,12,4,3,11,19,27,35,43,51,59,58,50,42,34,26,18,10,2,1,9,17,25,33,41,49,57,56,48,40,32,24,16,8,0};

const String WIFIlogo= "00bbbb000bbbbbb0bb0000bbb0bbbb0b0bbbbbb0bb0000bb000bb000000bb000";
const String Connectedlogo = "0076660007600660060000600660066000666600000660000006660000066d00";
const String dot = "0000000000000000007777000077770000777700007777000000000000000000";
const String specialized = "009aa90000aa900009a900000aa000009aaaaa900000a900000a900000090000";
const String arrow = "0000000000077000007777000777777077777777000770000007700000000000";

// 16个颜色的RGB数值
const char *colorList[16] = {"000000000", "029043083", "126037083", "000135081", 
					"171082054", "095087079", "194195199", "255241232", 
					"255000077", "255163000", "255255039", "000231086", 
					"041173255", "131118156", "255119168", "255204170"};

int ConnectFlag = 0;
int Brightness = 2;
int LikedIndex = 0;
int BtnState = 0;
String IPaddress = "";
String num[] = {NUM0, NUM1, NUM2, NUM3, NUM4, NUM5, NUM6, NUM7, NUM8, NUM9};

String getContentType(String filename);
bool handleFileRead(String path);
void handleUserRequet();
int HexToDec(char x);
void changeLED();
void saveImage();
void likeImage();
void DeleteDIY();
void DeleteLIKED();
void SetBrightness();
void GetBrightness();
void ShowLOGO(String LOGOmess);
void DeleteEmoji(String name, String mess);
void SaveFile(String name, String mess);
void OnTouchClicked();
void SendWiFimess();
void DeleteWiFi();
void RotateBtn();
